package com.shenzhen.horselive.ui.fragment;

import android.content.Intent;
import android.graphics.Path;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.gyf.immersionbar.ImmersionBar;
import com.meiqia.meiqiasdk.util.MQIntentBuilder;
import com.shenzhen.horselive.R;
import com.shenzhen.horselive.User;
import com.shenzhen.horselive.adapter.MyViewPageAdapter;
import com.shenzhen.horselive.api.ApiFactory;
import com.shenzhen.horselive.base.BaseFragment;
import com.shenzhen.horselive.beans.CommResponseDataBean;
import com.shenzhen.horselive.databinding.FragmentHongBaoBinding;
import com.shenzhen.horselive.network.SchedulersCompat;
import com.shenzhen.horselive.presenter.ViewObserver;
import com.shenzhen.horselive.ui.activity.NoticesActivity;

import java.util.ArrayList;
import java.util.List;

public class HongBaoFragment extends BaseFragment {

    public static HongBaoFragment newInstance() {
        HongBaoFragment fragment = new HongBaoFragment();
        return fragment;
    }
    FragmentHongBaoBinding binding;
    @Override
    protected View getContentView(LayoutInflater inflater, ViewGroup viewGroup) {
        binding = FragmentHongBaoBinding.inflate(getLayoutInflater(),viewGroup,false);
        initViews();
        return binding.getRoot();
    }

    @Override
    public void onResume() {
        super.onResume();
        initData();
    }

    private void initData() {
        //查询总收益
        ApiFactory.getApiService().account(User.get().getMyInfo().getToken())
                .compose(SchedulersCompat.applyIoSchedulers())
                .safeSubscribe(new ViewObserver<CommResponseDataBean>(this) {
                    @Override
                    protected void onNextInActive(CommResponseDataBean commResponseDataBean) {
                       if (commResponseDataBean.isSuccess())
                       {
                           binding.tvTitle.setText("¥"+commResponseDataBean.getData());
                       }
                    }
                });
    }

    private void initViews() {
        List<Fragment>  list = new ArrayList<>();
        //开红包
        list.add(OpenHongBaoFragment.newInstance());
        list.add(EmptyFragment.newInstance());
//        list.add(new Fragment());
        List<String>  stringList = new ArrayList<>();
        stringList.add("抢红包");stringList.add("挖矿石");
        MyViewPageAdapter  adapter = new MyViewPageAdapter(getChildFragmentManager(),list,stringList);
        binding.viewpage.setScroll(false);
        binding.viewpage.setAdapter(adapter);
        binding.tabs.setupWithViewPager(binding.viewpage);
        //消息中心
        binding.imgMessage.setOnClickListener(onClickListener);
        //客服对话
        binding.imgKefu.setOnClickListener(onClickListener);

    }



    long   mlasttime;
    View.OnClickListener  onClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            long    time =  System.currentTimeMillis();
           if ((time-mlasttime)/1000<1)
           {
               return;
           }
           switch (v.getId())
           {
               case R.id.img_message:
                   //消息中心
                   startActivity(new Intent(getContext(), NoticesActivity.class));
                   break;
               case R.id.img_kefu:
                   //客服中心
                   Intent intent = new MQIntentBuilder(getContext()).build();
                   startActivity(intent);
                   break;
           }


        }
    };


    @Override
    public void initImmersionBar() {
//        ImmersionBar.with(this)
//                .fitsSystemWindows(true)
//                .statusBarColor(R.color.white)
//                .statusBarDarkFont(true)
//                .init();
    }
}